package com.next.muscu.data;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;


public class ExoTreeModel implements TreeModel {
	String root = "root";
	List<ExoTypeExo> data = null;
    private Vector<TreeModelListener> treeModelListeners =
        new Vector<TreeModelListener>();
    
	public ExoTreeModel(List<ExoTypeExo> data)
	{
		this.data = data;
	}
	
	@Override
	public void addTreeModelListener(TreeModelListener l) {
		treeModelListeners.addElement(l);

	}

	@Override
	public Object getChild(Object arg0, int arg1) {
		Object retour = null;
		if ((arg0 instanceof ExoTypeExo))
		{
			ExoTypeExo e = (ExoTypeExo) arg0;
			retour = (e.getExos().toArray())[arg1];
		}
		else if (arg0 instanceof String)
			retour = this.data.get(arg1);
		return retour;
	}

	@Override
	public int getChildCount(Object arg0) {
		int retour = 0;
		if ((arg0 instanceof ExoTypeExo))
		{
			ExoTypeExo e = (ExoTypeExo) arg0;
			retour = e.getExos().size();
		}
		else if (arg0 instanceof String)
			retour = this.data.size();
		return retour;
			
			
		
	}

	@Override
	public int getIndexOfChild(Object arg0, Object arg1) {
		int retour = -1;
		if ((arg0 instanceof ExoTypeExo) && arg1 instanceof Exo)
		{
			ExoTypeExo e = (ExoTypeExo) arg0;
			Iterator it = e.getExos().iterator();
			while(it.hasNext() && retour == -1)
			{
				it.equals(arg1);
				it.next();
			}
		}
		else if (arg0 instanceof String)
			retour = this.data.size();
		return retour;
	}

	@Override
	public Object getRoot() {
		return root;
	}

	@Override
	public boolean isLeaf(Object arg0) {
		if (arg0 instanceof Exo)
			return true;
		return false;
	}

	@Override
	public void removeTreeModelListener(TreeModelListener l) {
		treeModelListeners.removeElement(l);

	}

	@Override
	public void valueForPathChanged(TreePath arg0, Object arg1) {
		//Object[] path = arg0.getPath();
		//Object data = path[path.length];
		

	}

}
